package com.example.rabbitmq.config;

import com.example.rabbitmq.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQReturnConfig {

    @Bean("returnExchange")
    public Exchange returnExchange() {
        //默认持久化是true的，如果没有显示指定的话
        //可以通过durable(false)的方式来显示指定不需要持久化
        return ExchangeBuilder.topicExchange(Constants.RETURN_EXCHANGE).build();
    }

    @Bean("returnQueue")
    public Queue returnQueue() {
        //需要显示指定是否需要持久化
        return QueueBuilder.durable(Constants.RETURN_QUEUE).build();
    }

    @Bean("returnBinding")
    public Binding returnBinding(@Qualifier("returnExchange") Exchange exchange, @Qualifier("returnQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("return").noargs();
    }
}
